package com.heima.article.service.impl;

import com.heima.article.service.RedisLuaService;
import com.heima.common.constant.GlobalConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class RedisLuaServiceImpl implements RedisLuaService {
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    private static final DefaultRedisScript<Void> replaceListRedisScript=new DefaultRedisScript<>();
    static {
        replaceListRedisScript.setLocation(new ClassPathResource(GlobalConstant.REPLACE_LIST_LUA));
    }
    @Override
    public void replaceList(String key, List<String> arr) {
        log.info("repalce list, key->{}",key);
        stringRedisTemplate.execute(replaceListRedisScript,arr,key);
    }
}
